Golang bufio.ScanWords() function example
package bufio
ScanWords is a split function for a Scanner that returns each space-separated word of text, with surrounding spaces deleted. It will never return an empty string. The definition of space is set by unicode.IsSpace.
Golang bufio.ScanWords() function usage example
file, err := os.Open("words.txt")
if err != nil {
panic(err.Error())
}
defer file.Close()
reader := bufio.NewReader(file)
scanner := bufio.NewScanner(reader)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
fmt.Printf("%s ", scanner.Text())
}
Reference :
Advertisement
Something interesting
Tutorials
+10.3k Golang : Convert file unix timestamp to UTC time example
+17k Golang : Capture stdout of a child process and act according to the result
+4.7k JavaScript: Add marker function on Google Map
+8.3k Golang : Number guessing game with user input verification example
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+13.9k Golang : Get dimension(width and height) of image file
+11.3k Golang : Byte format example
+10.6k Golang : Resolve domain name to IP4 and IP6 addresses.
+5.8k Cash Flow : 50 days to pay your credit card debt
+10.5k Golang : Select region of interest with mouse click and crop from image
+22.1k Golang : Join arrays or slices example